let gulp    = require("gulp");
let {paths,proxyList} = require("./gulp.config");
let connect = require("gulp-connect");
let proxy = require('http-proxy-middleware')

function devConfig(){
    
function devStyles(){
    return gulp.src(paths.styles.src)
            .pipe(gulp.dest(paths.styles.dist))
            .pipe(connect.reload());
}

function devScripts(){
    return gulp.src(paths.scripts.src)
            .pipe(gulp.dest(paths.scripts.dist))
            .pipe(connect.reload());
}
function devHtml(){
    return gulp.src(paths.html.src)
            .pipe(gulp.dest(paths.html.dist))
            .pipe(connect.reload());
}
function useconnect(){
    return connect.server({
        root : "./dist",
        port : 8888,
        livereload: true,
        middleware : function(connect,opt){
            return [
                proxy("/zc",
                { target: 'https://www.zcool.com.cn/recommend/contentRecommend?pageSize=5&contentId=9197857_3&day=2018-12-04', 
                  changeOrigin: true,
                  pathRewrite : {
                      "^/zc" : ""
                  }  
            }),
                proxy("/mz",{
                    target:'https://lists.meizu.com/search/primary/autocomplete?callback=jQuery111306054334807346478_1563676781790&keyword=&_=1563676781791',
                    changeOrigin:true,
                    pathRewrite :{
                        "^/mz" : ""
                    }
                })
            ]
        }
    });
}

function watch(){
    gulp.watch(paths.styles.src,devStyles);
    gulp.watch(paths.scripts.src,devScripts);
    gulp.watch(paths.html.src,devHtml);
}

let dev = gulp.series(gulp.parallel(useconnect,watch));
return dev;
}

module.exports = devConfig;